package org.misalen.web.admin.controllers;

import org.misalen.web.database.repository.mysql.SysResourcesRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

@Controller
@RequestMapping(value = "/")
public class HomeController extends BaseController {
	@Autowired
	protected SysResourcesRepository sysResourcesRepository;

	/**
	 * 首页
	 * 
	 * @return 目标页面
	 */
	@RequestMapping(value = "/home/", method = { RequestMethod.GET }, produces = "application/json")
	public ModelAndView empty() {
		return new ModelAndView("/home/main");
	}

	/**
	 * 首页
	 * 
	 * @return 目标页面
	 */
	@RequestMapping(value = "/userTree", method = { RequestMethod.GET }, produces = "application/json")
	public @ResponseBody Object userTree() {
		return renderSuccess(sysResourcesRepository.findAdminTree(getShiroUser().getUserId()));
	}

	/**
	 * 首页
	 * 
	 * @return 目标页面
	 */
	@RequestMapping(value = "/", method = { RequestMethod.GET }, produces = "application/json")
	public ModelAndView home() {
		return new ModelAndView("redirect:/home/");
	}

}
